<?php
/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 5/25 0025
 * Time: 11:41
 */
//        $biz_content.="\"subject\":\"" . $subject . "\",\"body\":\"test\",";
//        $biz_content.="\"goods_detail\":[{\"goods_id\":\"apple-01\",\"goods_name\":\"ipad\",\"goods_category\":\"7788230\",\"price\":\"88.00\",\"quantity\":\"1\"},{\"goods_id\":\"apple-02\",\"goods_name\":\"iphone\",\"goods_category\":\"7788231\",\"price\":\"88.00\",\"quantity\":\"1\"}],";
//        $biz_content.="\"operator_id\":\"op001\",\"store_id\":\"pudong001\",\"terminal_id\":\"t_001\",";
//        $biz_content.="\"timeout_express\":\"5m\"}";
namespace app\api\model;


class Alipay
{

    public function __construct()
    {
        defined("AOP_SDK_WORK_DIR") or define("AOP_SDK_WORK_DIR",RUNTIME_PATH."log".DIRECTORY_SEPARATOR."alipay");
        include_once EXTEND_PATH."alipay".DIRECTORY_SEPARATOR."function.inc.php";
        include_once EXTEND_PATH."alipay".DIRECTORY_SEPARATOR."AopSdk.php";
    }

    /**
     * 生成一个支付宝预订单
     * @param $out_trade_no
     * @param $total_amount
     * @return bool
     */
    public function getqrurl($out_trade_no,$total_amount){
//        $NotifyUrl="http://e.xwdcook.com/index.php/Home/Apiv5/alipaynotify";
        $NotifyUrl=url("Notify/alipaynotify",null,null,$_SERVER["HTTP_HOST"]);
        $param=[
            "out_trade_no"=>$out_trade_no,
            "total_amount"=>$total_amount,
            "discountable_amount"=>"0.00",
            "subject"=>"SUBJECT",
            "body"=>"test",
            "timeout_express"=>"5m"
        ];
        $request = new \AlipayTradePrecreateRequest();
        $request->setBizContent ( json_encode($param) );
        $request->setNotifyUrl ($NotifyUrl);
        $response = aopclient_request_execute( $request );
        if(!empty($response)){
            if(isset($response->alipay_trade_precreate_response) and $response->alipay_trade_precreate_response->code=="10000"){
                return $response->alipay_trade_precreate_response->qr_code;//正常返回二维码
            }
        }else{
            return false;
        }

    }
}